<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function* add(a) {
            // a = 3
            let b = 2 * (yield (a - 1));
            // b = 12
            let c = yield (b / 4);
            // c = 1
            return (a + b + c);
        }
        let result = add(3);

        console.log(result.next());  // 2
        console.log(result.next(6)); // 3
        console.log(result.next(1)); // 16
        
        // next()函数的实参，会把上一个结果替换掉
    </script>
</body>

</html>